package com.work.lxykeeper.utils;

import android.text.TextUtils;

import com.work.lxykeeper.cache.Ckey;
import com.work.lxykeeper.cache.SPutils;
import com.work.lxykeeper.httpretrofit.Url;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by WZ on 2020/12/1.
 * description:
 * //        signStr = "{" appId ":weiyu," time ":1605579203455," str ":" appId + time +
 * //                appId + accesskey进行MD5加密
 * //        "," accesskey ":" AA4GNADCBiQKBgQCU7E "}"
 */
public class SignStrUtil {
    public static String getSign() {
        String signStr;
        String accesskey = Url.AccesKey;
        String appId = Url.APPID;
        long time = 0;
        if (!TextUtils.isEmpty(SPutils.get(Ckey.TIME))) {
            time = System.currentTimeMillis() + Long.parseLong(SPutils.get(Ckey.TIME));
        } else {
            time = System.currentTimeMillis();
        }
        String md5 = appId + time + appId + accesskey;
        String str = MD5Utils.get32MD5Str(md5);
        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("time", time + "");
        map.put("str", str);
        map.put("accesskey", accesskey);

        signStr = RSAUtils.encryptByPublicKey(JsonUtils.parseBeantojson(map),SPutils.get(Ckey.PUBKEY));
        LogUtils.d("signStr===" + JsonUtils.parseBeantojson(map));
        LogUtils.d("signStr===" + signStr);
        LogUtils.d("时间差===" + SPutils.get(Ckey.TIME));
        LogUtils.d("md5===" + md5);
        return signStr;
    }
}
